package cn.itcast.myapplication.fragment;

import android.os.Bundle;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SeekBar;

import cn.itcast.myapplication.R;
import cn.itcast.myapplication.databinding.FragmentMasterBinding;
import cn.itcast.myapplication.viewemodel.MyViewModel;
import cn.itcast.myapplication.viewemodel.NavViewModel;


public class MasterFragment extends Fragment {


    @Override
    public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {

        final NavViewModel navViewModel;
        navViewModel=new ViewModelProvider(getActivity()).get(NavViewModel.class);
        FragmentMasterBinding binding;
        binding= DataBindingUtil.inflate(inflater,R.layout.fragment_master,container,false);
        binding.setData(navViewModel);
        binding.setLifecycleOwner(getActivity());
        //点击事件
        binding.button8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                NavController navController= Navigation.findNavController(view);

                navController.navigate(R.id.action_masterFragment_to_blankFragment);


            }
        });

//           binding.seekBar.setProgress(navViewModel.getNumber().getValue());

           binding.seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
               @Override
               public void onProgressChanged(SeekBar seekBar, int position, boolean b) {
                    navViewModel.getNumber().setValue(position);
               }

               @Override
               public void onStartTrackingTouch(SeekBar seekBar) {

               }

               @Override
               public void onStopTrackingTouch(SeekBar seekBar) {

               }
           });


        // Inflate the layout for this fragment
        return binding.getRoot();



           }

    }